package com.rslai.base.tool.servertest.config;

import com.rslai.base.tool.servertest.annotation.Property;
import com.rslai.base.tool.servertest.command.StepCommand;
import com.rslai.base.tool.servertest.command.Transform;
import com.rslai.base.tool.servertest.command.TransformStepCommand;

public class TransformStepConfig extends StepConfig {

    @Property(value = "class", required = true)
    String transform;

    public StepCommand createCommand() {
        try {
            Class t = Class.forName(this.transform);
            Object instance = t.newInstance();
            if ((instance instanceof Transform)) {
                Transform transform = (Transform) instance;
                return new TransformStepCommand(transform);
            }
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(String.format("未找到指定的Transform对象： %s", new Object[]{this.transform}), e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(String.format("创建Transform对象失败: %s", new Object[]{this.transform}), e);
        } catch (InstantiationException e) {
            throw new RuntimeException(String.format("创建Transform对象失败: %s", new Object[]{this.transform}), e);
        }
        return null;
    }
}
